﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DoeObjects;
using System.Web.Mvc;
using DoeLibsMVC.Security;

namespace DoeLibsMVC.Models
{
	public class UserDeleteModel
	{
		public UserDeleteModel()
		{
			_staffMembers = new List<User>();
			List<User> users = User.getUsersOfCategory(UserCategoryHelper.STAFF_CATEGORY);
			foreach (User u in users)
				if (u.Activated)
					_staffMembers.Add(u);
		}

		public UserDeleteModel(int fromUserId) : this()
		{
			for (int i = 0; i < _staffMembers.Count; i++)
			{
				if (_staffMembers[i].UserId == fromUserId)
				{
					_staffMembers.RemoveAt(i);
					break;
				}
			}
		}

		public User FromUser;

		public List<Loanable> UserLoanables;
		public List<int> TransferLoanablesIds;
		public int ToUserId { get; set; }

		private List<User> _staffMembers;
		public IEnumerable<SelectListItem> StaffMembers
		{
			get
			{
				var dynStaffMembers = _staffMembers.Select(u => new { id = u.UserId, display = string.Format("{0} {1} ({2})", u.FirstName, u.LastName, u.Room) }).ToList();
				return new SelectList(dynStaffMembers, "id", "display");
			}
		}
	}
}